import Vue from 'vue'
import Router from 'vue-router'

// 在开发环境中不使用延迟加载，因为延迟加载太多页面会导致webpack热更新太慢。 所以只有在生产中使用延迟加载;

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/index.vue'

/**
* hidden: true                   如果`hidden：true`不会显示在侧边栏中（默认为false）
* alwaysShow: true               如果设置为true，将始终显示根菜单，无论其子路径长度如何
*                                如果没有设置alwaysShow，只有多个路径下的孩子
*                                它将成为嵌套模式，否则不显示根菜单
* redirect: noredirect           如果`redirect：noredirect`不会在面包屑中重定向
* name:'router-name'             该名称由<keep-alive>使用（必须设置!!!）
* meta : {
    title: 'title'               子菜单和面包屑中的名称显示（推荐级）
    icon: 'svg-name'             侧边栏中的图标显示，
  }
**/
// 不需要权限的路由
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404/index'),
    hidden: true
  },
]
export const constantRouterMap = [
  /*下面的都是layout里面的页面路由了 */
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Index', //路由名字和子菜单的路径必须区分，不然会有警告
    hidden: true,
    meta: {
      title: '首页',
      icon: 'el-icon-s-home'
    },
    children: [{
      path: 'index',
      component: () => import('@/views/index/index'),
      roles: []
    }]
  },
  {
    path: '/purchase',
    component: Layout,
    name: 'Purchase',
    meta: {
      title: '采购管理',
      icon: 'el-icon-s-shop'
    },
    children: [{
        path: 'buyList',
        name: 'BuyList',
        component: () => import('@/views/purchase/buyList/index'),
        meta: {
          title: '安心行采购订单',
          icon: 'el-icon-tickets'
        },
        roles: []
      },
      {
        path: 'buy',
        name: 'Buy',
        component: () => import('@/views/purchase/buy/index'),
        meta: {
          title: '新建采购',
          icon: 'el-icon-tickets'
        },
        roles: [{
          name: 'Btn_buy_xz',
          title: '新增-btn'
        }, ]
      },
      {
        path: 'plist3',
        name: 'Plist3',
        component: () => import('@/views/purchase/plist3/index'),
        meta: {
          title: '安心行原厂备件采购',
          icon: 'el-icon-tickets'
        },
        roles: []
      },
    ]
  },
  {
    path: '/product',
    component: Layout,
    name: 'Product',
    meta: {
      title: '产品管理',
      icon: 'el-icon-s-shop'
    },
    children: [{
      path: 'goodsList',
      name: 'GoodList',
      component: () => import('@/views/product/goodsList/index'),
      meta: {
        title: '安心行备件产品',
        icon: 'el-icon-tickets'
      },
      roles: []
    }, ]
  },
  {
    path: '/fund',
    component: Layout,
    name: 'Fund',
    meta: {
      title: '基金管理',
      icon: 'el-icon-s-marketing'
    },
    children: [{
      path: 'income',
      name: 'Income',
      component: () => import('@/views/fund/income/index'),
      meta: {
        title: '收益明细',
        icon: 'el-icon-tickets'
      },
      roles: []
    }, ]
  },
  {
    path: '/setting',
    component: Layout,
    name: 'Setting',
    meta: {
      title: '系统配置',
      icon: 'el-icon-s-tools'
    },
    children: [{
        path: 'userList',
        name: 'UserList',
        component: () => import('@/views/setting/user/userList'),
        meta: {
          title: '用户列表',
          icon: 'el-icon-tickets'
        },
        roles: [{
          name: 'Btn_rolesList_yw',
          title: '业务消息-btn'
        }, ]
      },
      {
        path: 'rolesList',
        name: 'RolesList',
        component: () => import('@/views/setting/roles/rolesList'),
        meta: {
          title: '角色列表',
          icon: 'el-icon-tickets'
        },
        roles: [{
            name: 'Btn_rolesList_yw',
            title: '业务消息-btn'
          },
          {
            name: 'Btn_rolesList_kc',
            title: '库存预警-btn'
          },
        ]

      },
    ]
  },
  {
    path: '/osjj',
    component: Layout,
    name: 'Osjj',
    meta: {
      title: '欧式家具',
      icon: 'el-icon-s-tools'
    },
    children: [{
        path: 'pc',
        name: 'Pc',
        component: () => import('@/views/osjj/pc/pcList'),
        meta: {
          title: '产品列表',
          icon: 'el-icon-tickets'
        },
      },
    ]
  },
  {
    path: '/xcx',
    component: Layout,
    name: 'Xcx',
    meta: {
      title: '销售管理',
      icon: 'el-icon-s-tools'
    },
    children: [{
        path: 'musicList',
        name: 'MusicList',
        component: () => import('@/views/xcx/musicList'),
        meta: {
          title: '销售列表',
          icon: 'el-icon-tickets'
        },
        roles: [{
          name: 'Btn_rolesList_yw',
          title: '业务消息-btn'
        }, ]
      },
      {
        path: 'blog',
        name: 'Blog',
        component: () => import('@/views/xcx/blog'),
        meta: {
          title: '发货单',
          icon: 'el-icon-tickets'
        },
        roles: [{
            name: 'Btn_rolesList_yw',
            title: '业务消息-btn'
          },
          {
            name: 'Btn_rolesList_kc',
            title: '库存预警-btn'
          },
        ]

      },
      {
        path: 'xcxSetting',
        name: 'XcxSetting',
        component: () => import('@/views/xcx/setting'),
        meta: {
          title: '退货单',
          icon: 'el-icon-tickets'
        },
        roles: [{
            name: 'Btn_rolesList_yw',
            title: '业务消息-btn'
          },
          {
            name: 'Btn_rolesList_kc',
            title: '库存预警-btn'
          },
        ]

      },
    ]
  },
]

const createRouter = () => new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes,
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
